//
//  ViewController.m
//  AFN 框架
//
//  Created by 钟纪旺 on 2018/2/6.
//  Copyright © 2018年 钟纪旺. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "属性传值.h"
#import "回调传值.h"
@interface ViewController ()<UITextFieldDelegate>
{
    UITextField * textF;
}
@property (nonatomic,strong)NSArray *arr;
@property (nonatomic,strong)UITextField *textkong;
@property (nonatomic,strong)NSMutableDictionary *dddd;
@property (nonatomic,strong)UILabel *lab ;

@property (nonatomic,strong)UIButton *ShuXingbtn;
@property (nonatomic,strong)UIButton *HuiDiaobtn;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view, typically from a nib.
    //布局
    [self buju];
    //联网
    [self wangluo];
    //属性button
    [self 属性传值button];
    //回调button
    [self 回调传值button];
    //textF
    textF = [[UITextField alloc]init];
    textF.frame = CGRectMake(0, 300, self.view.frame.size.width, 30);
    textF.borderStyle = UITextBorderStyleRoundedRect;
    textF.textColor = [UIColor redColor];
    textF.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:textF];
    
}
-(void)buju{
    _textkong = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
     _textkong.backgroundColor = [UIColor redColor];
    
    
    
//    _lab = [[UILabel alloc]initWithFrame:CGRectMake(144, 144, 88, 66)];
//    _lab.text = @" 123";
//    _lab.textColor = [UIColor redColor];
//    [self.view addSubview:_lab];
   
    [self.view addSubview:_textkong];
    /*
    // Do any additional setup after loading the view, typically from a nib.
    //    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    //    _textField = [[dddd alloc]initWithFrame:CGRectMake(100, 100, self.view.frame.size.width, 44)];
    //    _textField.backgroundColor = [UIColor redColor];
    //    _textField.keyboardType = UIKeyboardTypeDecimalPad;
    //    [_textField addTarget:self
    //                  action:@selector(textFieldDidChange)
    //        forControlEvents:UIControlEventEditingChanged];
    //    [textField becomeFirstResponder];
    //    [self.view addSubview:_textField];
    //    view.backgroundColor = [UIColor redColor];
    //    [self.view addSubview:view];
    // [self aaa];
     */
    
}
- (void)属性传值button{
    _ShuXingbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 90, 90 ,90)];
    [_ShuXingbtn setTitle:@"属性传值" forState:0];
    _ShuXingbtn.backgroundColor = [UIColor redColor];
    [_ShuXingbtn addTarget:self action:@selector(属性传值) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_ShuXingbtn];
}
- (void)回调传值button{
    _HuiDiaobtn = [[UIButton alloc]initWithFrame:CGRectMake(0,180, 90, 90 )];
    [_HuiDiaobtn setTitle:@"回调传值" forState:0];
    _HuiDiaobtn.backgroundColor =[UIColor redColor];
    [_HuiDiaobtn addTarget:self action:@selector(回调传值) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_HuiDiaobtn];
    
}
- (void)wangluo{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *url = @"https://aapi.tomorrow.cn.com/service/oauth/login";
    NSDictionary *param = @{
                            @"email":@"t@t.20",
                            @"lang":@"en",
                            @"password":@"111111"
                            };
    [manager POST:url parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        _dddd = responseObject;
        
        
        NSLog(@"请求成功--->%@",_dddd);
        _arr = responseObject;
        // NSLog(@"%@",_arr);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求失败--->%@",error);
    }];
    
}
- (void)属性传值{
    //定义属性正向传值
    属性传值 * newView = [[属性传值 alloc]init];
    newView.dic =_dddd;
    [self.navigationController pushViewController:newView animated:YES];
    
}
-(void)回调传值{
    回调传值 * newView = [[回调传值 alloc]init];
    //核心代码为block属性赋值
    newView.pushValueString = ^(NSString *str) {
        textF.text = str;
    };
    [self.navigationController pushViewController:newView animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
